<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>订单管理</title>
    <link rel="stylesheet" type="text/css" href="../css/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../css/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../css/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../css/style.css">
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../js/datagrid-detailview.js"></script>
    <script type="text/javascript" src="../js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../js/config.js"></script>
</head>
<body>
<table id="dg" title="" class="easyui-datagrid" fit="true" multiSort="true"
       toolbar="#query" footer="#toolbar" pagination="true" rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="platformId" sortable="true" width="50" formatter="CommonUtil.platformFormatter">平台名称</th>
        <th field="shopId" sortable="true" width="100" formatter="CommonUtil.shopFormatter">店铺名称</th>
        <th field="contactName" sortable="true" width="50">联系人</th>
        <th field="contactTel" sortable="true" width="50">联系电话</th>
        <th field="contactAddress" sortable="true" width="50">联系地址</th>
        <th field="orderTime" sortable="true" width="50" formatter="CommonUtil.dateFormatter">下单时间</th>
        <th field="orderRemark" sortable="true" width="50">订单备注</th>
        <th field="status" sortable="true" width="50" formatter="CommonUtil.OrderStatusFormatter">状态</th>
        <th field="oldId" sortable="true" width="50">原ID</th>
        <th field="newId" sortable="true" width="50">新ID</th>
        <th field="createUser" sortable="true" width="50">创建人</th>
        <th field="createTime" sortable="true" width="50" formatter="CommonUtil.dateFormatter">创建时间</th>
        <th field="updateUser" sortable="true" width="50">修改人</th>
        <th field="updateTime" sortable="true" width="50" formatter="CommonUtil.dateFormatter">修改时间</th>
    </tr>
    </thead>
</table>
<div id="query" style="padding:2px 5px;">
    订单状态:
    <select id="qStatus" class="easyui-combobox" panelHeight="auto" style="width:100px">
    </select>
    外卖平台:
    <select id="qPlatformId" class="easyui-combobox" panelHeight="auto" style="width:100px">
    </select>
    店铺名称:
    <select id="qShopId" class="easyui-combobox" panelHeight="auto" style="width:200px">
    </select>
    联系人: <input id="qContactName" class="easyui-textbox" style="width:110px"/>
    联系电话: <input id="qContactTel" class="easyui-textbox" style="width:110px"/>
    联系地址: <input id="qContactAddress" class="easyui-textbox" style="width:110px"/>
    <br/>
    下单时间:<input id="qStartOrderTime" class="easyui-datetimebox"
                data-options="formatter:CommonUtil.myFormatter,parser:CommonUtil.myParser"
                style="width:150px"/>
    ~
    <input id="qEndOrderTime" class="easyui-datetimebox"
           data-options="formatter:CommonUtil.myFormatter,parser:CommonUtil.myParser"
           style="width:150px"/>
    <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="Order.loadData()">查询</a>
</div>
<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true">订单下载</a>
</div>
<script type="text/javascript">
    $(function () {
        Order.loadOrderStatus();
        Order.loadPlatform();
        Order.loadShop();
    });

    window.Order = {
        loadOrderStatus: function () {
            $('#qStatus').combobox({
                method: 'GET',
                url: window.BASEPATH + 'code/orderStatus',
                valueField: 'id',
                textField: 'text',
                loadFilter: function (data) {
                    if (data.suc == true) {
                        var rtn = data.result.rows;
                        window.OrderStatus_Data = rtn;
                        return rtn;
                    } else {
                        return null;
                    }
                }
            });
        },
        loadPlatform: function () {
            $('#qPlatformId').combobox({
                method: 'GET',
                url: window.BASEPATH + 'platform/dropdown',
                valueField: 'id',
                textField: 'text',
                loadFilter: function (data) {
                    if (data.suc == true) {
                        var rtn = data.result.rows;
                        window.Platform_Data = rtn;
                        return rtn;
                    } else {
                        return null;
                    }
                }
            });
        },
        loadShop: function () {
            $('#qShopId').combobox({
                method: 'GET',
                url: window.BASEPATH + 'shop/dropdown',
                valueField: 'id',
                textField: 'text',
                loadFilter: function (data) {
                    if (data.suc == true) {
                        var rtn = data.result.rows;
                        window.Shop_Data = rtn;
                        return rtn;
                    } else {
                        return null;
                    }
                }
            });
        },
        loadData: function () {
            $('#dg').datagrid({
                        method: 'GET',
                        url: window.BASEPATH + 'order',
                        queryParams: {
                            status: $('#qStatus').combobox('getValue'),
                            platformId: $('#qPlatformId').combobox('getValue'),
                            shopId: $('#qShopId').combobox('getValue'),
                            contactName: $("#qContactName").val(),
                            contactTel: $("#qContactTel").val(),
                            contactAddress: $("#qContactAddress").val(),
                            startOrderTime: CommonUtil.getMillisecond($('#qStartOrderTime').combobox('getValue')),
                            endOrderTime: CommonUtil.getMillisecond($('#qEndOrderTime').combobox('getValue'))
                        },
                        loadFilter: function (data) {
                            if (data.suc == true) {
                                return data.result;
                            } else {
                                $.messager.show({
                                    title: 'Error',
                                    msg: data.message
                                });
                                return null;
                            }
                        },
                        view: detailview,
                        detailFormatter: function (index, row) {
                            return '<div style="padding:2px"><table class="ddv"></table></div>';
                        },
                        onExpandRow: function (index, row) {
                            var ddv = $(this).datagrid('getRowDetail', index).find('table.ddv');
                            ddv.datagrid({
                                url: window.BASEPATH + 'orderDetail/orderId/' + row.id,
                                method: 'GET',
                                fitColumns: true,
                                singleSelect: true,
                                rownumbers: true,
                                loadMsg: '',
                                height: 'auto',
                                columns: [
                                    [
                                        {field: 'barcode', title: '商品条码', width: 100},
                                        {field: 'dishName', title: '商品名称', width: 100 },
                                        {field: 'orderOrder', title: '点单顺序', width: 50 },
                                        { field: 'quantity', title: '数量', width: 50   }
                                    ]
                                ],
                                onResize: function () {
                                    $('#dg').datagrid('fixDetailRowHeight', index);
                                },
                                loadFilter: function (data) {
                                    if (data.suc == true) {
                                        return data.result;
                                    } else {
                                        $.messager.show({
                                            title: 'Error',
                                            msg: data.message
                                        });
                                        return null;
                                    }
                                },
                                onLoadSuccess: function () {
                                    setTimeout(function () {
                                        $('#dg').datagrid('fixDetailRowHeight', index);
                                    }, 0);
                                }
                            });
                            $('#dg').datagrid('fixDetailRowHeight', index);
                        }
                    }
            )
            ;
        }
    }
</script>
</body>
</html>